package com.ft.f_springboot_route.service.impl;


import com.ft.f_springboot_route.bean.Route;
import com.ft.f_springboot_route.mapper.RouteMapper;
import com.ft.f_springboot_route.service.RouteService;
import com.ft.f_springboot_route.utils.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RouteServiceImpl implements RouteService {


    @Autowired
    private RouteMapper routeMapper;

    @Override
    public Pager<Route> selectRouteList(String titleName,  Integer currentPage) {

        if(currentPage == null || currentPage < 0){
            currentPage = 1;
        }

        Pager<Route> pager = new Pager<>();
        pager.setPageSize(4);
        pager.setList(routeMapper.selectRouteList(titleName,(currentPage-1)*4));
        pager.setCurrentPage(currentPage);
        pager.setTotal(routeMapper.getTotal(titleName));

        return pager;
    }

    @Override
    public List<Route> toRouteList() {
        return routeMapper.toRouteList();
    }

    @Override
    public Route selectRoute(Integer routeId) {
        return routeMapper.selectRoute(routeId);
    }

    @Override
    public void addRoute(Route route) {
        routeMapper.addRoute(route);
    }

    @Override
    public void editRoute(Route route) {
        routeMapper.editRoute(route);
    }

    @Override
    public void deleteRoute(Integer routeId) {
        routeMapper.deleteRoute(routeId);
    }

}
